﻿using AutoMapper;
using B.S.Backtrack.Domain.Entities;
using B.S.Backtrack.ErrorCode;
using B.S.Backtrack.Infrastructure.Interface;
using B.S.Backtrack.Read.API.Application.Command.Cultures;
using MediatR;

namespace B.S.Backtrack.Read.API.Application.CommandHandler.Cultures
{
    public class QueryHealthHandler : IRequestHandler<QueryHealthCommand, ApiResult<List<Health>>>
    {
        private readonly IBaseRepository<Health> heaRep;
        private readonly IMapper mapper;

        public QueryHealthHandler(IBaseRepository<Health> heaRep,IMapper mapper)
        {
            this.heaRep = heaRep;
            this.mapper = mapper;
        }
        public Task<ApiResult<List<Health>>> Handle(QueryHealthCommand request, CancellationToken cancellationToken)
        {
            ApiResult<List<Health>> result = new ApiResult<List<Health>>();
            var list = heaRep.GetAll().Where(x => x.ProductId == request.ProductId&&!x.IsDel);
            result.Code = ApiEnums.查询成功;
            result.Msg = ApiEnums.查询成功.ToString();
            result.Data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
